from appium import webdriver
from selenium.webdriver.common.by import By


class DriverManage:
    desired_caps = {
        "platformName": "Android",
        "deviceName": "emulator-5554",  # 注意，这个值改为自己手机的devicename 可以通过adb devices 查看
        "automationName": "UIAutomator2",
        "appPackage": "org.cnodejs.android.md",  # 启动包名
        "appActivity": ".ui.activity.LaunchActivity"  # 启动activity名称
    }

    @staticmethod
    def get_driver():
        driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', DriverManage.desired_caps)
        driver.implicitly_wait(10)
        return driver


if __name__ == '__main__':
    driver = DriverManage.get_driver()
    imgbtn = driver.find_element(By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("org.cnodejs.android.md:id/toolbar").childSelector(new UiSelector().className("android.widget.ImageButton"))')
    # imgbtn = driver.find_element_by_android_uiautomator('new UiSelector().resourceId("org.cnodejs.android.md:id/toolbar").childSelector(new UiSelector().className("android.widget.ImageButton"))')
    imgbtn.click()